# 定义表

from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy import Column, Integer, String

Base = declarative_base()  # 创建基类


# 所有的实体类需要继承基类
class User(Base):
    __tablename__ = 'user'  # 定义表名
    id = Column(Integer, primary_key=True, autoincrement=True)  # 定义主键类型，id增长方式自增长
    username = Column(String(32), nullable=False)
    password = Column(String(32), nullable=False)
    gender = Column(Integer, nullable=False)
    age = Column(Integer, nullable=False)
    email = Column(String(32), nullable=False)
    address = Column(String(255), nullable=False)

    # 自定义json序列化
    def JsonMarshal(self):
        return {
            "id": self.id,
            "username": self.username,
            "password": self.password,
            "gender": self.gender,
            "age": self.age,
            "email": self.email,
            "address": self.address
        }

